import{
    CHANGE_INPUT_VALUE,
    DELETE_TODO_ITEM,
    ADD_TOTO_ITEM,
    INIT_LIST_ACTION
} from './actionTypes'
const defaultState = {
    inputValue: '',
    list: ['aaa','aaa']
}
export default (state = defaultState, action) => {
    // console.log(state, action)
    if(action.type === CHANGE_INPUT_VALUE) {
        const newState = JSON.parse(JSON.stringify(state))
        newState.inputValue = action.value;
        return newState;
    }
    if(action.type === ADD_TOTO_ITEM) {
        const newState = JSON.parse(JSON.stringify(state))
        newState.list.push(newState.inputValue);
        newState.inputValue = '';
        return newState;
    }
    if(action.type === DELETE_TODO_ITEM) {
        const newState = JSON.parse(JSON.stringify(state))
        newState.list.splice(action.index, 1);
        newState.inputValue = '';
        return newState;
    }
    if(action.type === INIT_LIST_ACTION) {
        const newState = JSON.parse(JSON.stringify(state))
        newState.list = action.data;
        return newState;
    }
    return state;
}